//
//  FrequencyBackground.m
//  SKPAD
//
//  Created by admin@amonline.com.cn on 15/5/13.
//  Copyright (c) 2015年 amo. All rights reserved.
//

#import "FrequencyBackground.h"

@implementation FrequencyBackground

//代码创建初始化
-(id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        _trackLayerBackground = [CALayer layer];
        _trackLayerBackground.backgroundColor = [UIColor clearColor].CGColor;
        _backgroundView = (id)[UIImage imageNamed:@"eq_background.png"].CGImage;
        _trackLayerBackground.contents =_backgroundView;
        _trackLayerBackground.bounds = frame;
        
        
        _shapeLayer = [CAShapeLayer layer];
        _shapeLayer.backgroundColor = [UIColor clearColor].CGColor;
        UIColor * lightBlue = [UIColor colorWithRed:51.0/255 green:254.0/255 blue:255.0/255 alpha:1];
        _shapeLayer.strokeColor = lightBlue.CGColor;
        _shapeLayer.bounds = frame;
    }
    return  self;
}
- (void)drawInContext:(CGContextRef)contextRef
{

}

-(void)updateWithPosition:(CGRect)bounds
{
    //设置图层中心位置
    self.trackLayerBackground.position = CGPointMake(CGRectGetWidth(bounds)/2.0, CGRectGetHeight(bounds)/2.0);
    self.shapeLayer.position = CGPointMake(CGRectGetWidth(bounds)/2.0, CGRectGetHeight(bounds)/2.0);
    [self updateShapeLayer];
}

-(void) updateShapeLayer
{
    UIBezierPath * path = [UIBezierPath bezierPath];
        path.lineCapStyle = kCGLineCapRound;
    path.lineJoinStyle = kCGLineCapRound;

    [path moveToPoint:CGPointMake(self.bounds.origin.x, self.bounds.size.height/2)];
    //[path addLineToPoint:CGPointMake(self.bounds.size.width/4, self.bounds.size.height/4)];
    //[path addLineToPoint:CGPointMake(self.bounds.size.width/2, self.bounds.size.height/2)];
    //[path addLineToPoint:CGPointMake(self.bounds.size.width/4*3, self.bounds.size.height/4*3)];
    //[path addLineToPoint:CGPointMake(self.bounds.size.width, self.bounds.size.height/4*3)];
    
    
    [path addQuadCurveToPoint:CGPointMake(self.bounds.size.width/4, self.bounds.size.height/2)
                 controlPoint:CGPointMake(self.bounds.origin.x/4, -100)];
    [path closePath];
    //[path moveToPoint:CGPointMake(self.bounds.origin.x, self.bounds.size.height/2)];
    //[path addLineToPoint:CGPointMake(self.bounds.size.width, self.bounds.size.height/2)];

    [path stroke];
    [path fill];
    self.shapeLayer.path = path.CGPath;
    
}
@end